from flask import Blueprint
import json
from app.models import cls_to_dict, AvgMoneyCity,AlchemyEncoder

from flask import jsonify

dbm = Blueprint("dbm", __name__)


# 返回json(方法一)
@dbm.route("/json1")
def db1():
    data = list(AvgMoneyCity.query.all())
    return jsonify(list(map(cls_to_dict, data)))


# 返回json(方法二)
@dbm.route('/json2', methods=["GET"])
def jk():
    rs_gamc = AvgMoneyCity.query.all()
    return json.dumps(rs_gamc, cls=AlchemyEncoder)
